﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace PloobsEngine.SceneControl
{
   public enum GammaType
    {
        Normal, Simple,InvertNormal, InvertSimple,InvertVerySimple,VerySimple
    }

    /// <summary>
    /// OLHAR http://mynameismjp.wordpress.com/2009/12/31/correcting-xnas-gamma-correction/
    /// SOLUCAO MAIS ELEGANTE PARA PCS --  mudar o render state pelo effect apos o ultimo efeito aplicado
    /// </summary>
    public class GammaCorrectionPostEffect : IPostEffect
    {
        public GammaCorrectionPostEffect(GammaType type)
        {
            this._gType  = type;
        }

        #region IPostEffect Members

        Effect effect = null;

        private GammaType _gType;

        public void Draw(IRenderHelper rHelper, Microsoft.Xna.Framework.GameTime gt, Microsoft.Xna.Framework.Rectangle screenRec, IWorld world)
        {
            ///Draw a quad using the "effect", passing the CurrentImage as a Parameter            
            rHelper.RenderTextureToFullScreenSpriteBatch(PrincipalConstants.CurrentImage, effect);
        }

        public void init(EngineStuff engine)
        {
            ///Load the asset
            effect = EngineStuff.InternalContentManager.GetAsset<Effect>("gamma");
            //effect = EngineStuff.CustomContentManager.GetAsset<Effect>("..\\Content\\Effects\\gamma");
            switch (_gType)
            {
                case GammaType.Normal:
                    effect.CurrentTechnique = effect.Techniques[0];
                    break;
                case GammaType.Simple:
                    effect.CurrentTechnique = effect.Techniques[1];
                    break;
                case GammaType.InvertNormal:
                    effect.CurrentTechnique = effect.Techniques[2];
                    break;
                case GammaType.InvertSimple:
                    effect.CurrentTechnique = effect.Techniques[3];
                    break;
                case GammaType.VerySimple:
                    effect.CurrentTechnique = effect.Techniques[4];
                    break;
                case GammaType.InvertVerySimple:
                    effect.CurrentTechnique = effect.Techniques[5];
                    break;
                default:
                    break;
            }
        }

        #endregion

    }
}
